package com.example.myapp.Listviewloading;

import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.myapp.R;
import com.sak.ultilviewlib.adapter.BaseFooterAdapter;
import com.sak.ultilviewlib.util.MeasureTools;

public class MyFooterAdapter extends BaseFooterAdapter {

    private ImageView loading;

    private float pull_distance=0;
    private TextView msg;
    public MyFooterAdapter(Context context) {
        super(context);
    }

    @Override
    public View getFooterView() {
        View mView = mInflater.inflate(R.layout.footer_refresh_layout, null, false);
        loading = (ImageView) mView.findViewById(R.id.loading);
        msg= (TextView) mView.findViewById(R.id.msg);
        MeasureTools.measureView(mView);
        loading.setImageResource(R.drawable.up);
        return mView;
    }
/**上拉*/
    @Override
    public void pullViewToRefresh(int deltaY) {
        //这里乘以0.3 是因为UltimateRefreshView 源码中对于滑动有0.3的阻尼系数，为了保持一致
        pull_distance=pull_distance+deltaY*0.3f;
        msg.setText("释放加载");
        loading.setImageResource(R.drawable.down);
    }
    /**拉到头*/
    @Override
    public void releaseViewToRefresh(int deltaY) {


    }

    /**松手*/
    @Override
    public void footerRefreshing() {
        msg.setText("正在加载");
        loading.setImageResource(R.drawable.qq_loading);
        AnimationDrawable mAnimationDrawable= (AnimationDrawable) loading.getDrawable();
        mAnimationDrawable.start();
    }

    @Override
    public void footerRefreshComplete() {
        loading.setImageResource(R.drawable.gpv);
        pull_distance=0;
    }
}
